const app = getApp()
import Dialog from '@vant/weapp/dialog/dialog';
import {
  showMsg
} from '../../../../utils/config.js'
import {
    reqGetPreId,
} from '../../../../request/api.js';
Page({
  data: {
    navHeight: app.globalData.navHeight + 'px', //头部距离
    bottomHeight: app.globalData.bottomHeight + 'px', //iphone底部距离
    roomName: "",
    list: ['爸爸', '妈妈', '爷爷', '奶奶', '外公', '外婆', '哥哥', '弟弟', '姐姐', '妹妹', '朋友', '同事'],

    role:"",
    homeName:"",
    homeId:"",
  },

  onLoad(options) {
      console.log(options,'options');
      this.setData({
        role:options.role,
        homeName:options.homeName,
        homeId:options.homeId
      })
  },
  onShow() {

  },

  getName(item) {
    this.setData({
      roomName: item.currentTarget.dataset.item
    })
  },

  onAdd(){
    if (this.data.roomName=='') return showMsg('请输入成员名称');
  },
  onShareAppMessage(res) {
    console.log(res);
    if (res.from === 'button') {
      let shareUserId = wx.getStorageSync('userId');
      const promise = new Promise((resolve, reject) => {
        reqGetPreId({
          role: this.data.role,
          remark: this.data.roomName
        }).then(res => {
          console.log(res, '111');
          if (res.code != 20000) return showMsg(res.message);
          resolve({
            title: `${wx.getStorageSync('nickname')}邀请您加入${this.data.homeName}`,
            imagePath: './thumb.jpg',
            path: `/pages/index/index?preId=${res.data.preId}&homeId=${this.data.homeId}&shareUserId=${shareUserId}&nickname=${wx.getStorageSync('nickname')}&homeName=${this.data.homeName}&startTime=${new Date().getTime()}&totalTime=86400000`,
          })
        })
      })
      return {
        // 失效时间24小时  totalTime=86400000毫秒
        title: `${wx.getStorageSync('nickname')}邀请您加入${this.data.homeName}`,
        imagePath: './thumb.jpg',
        path: `/pages/index/index?shareUserId=${shareUserId}&startTime=${new Date().getTime()}&totalTime=86400000`,
        promise
      }
    }
  },

})